package com.yonglian.management.service.impl;

import com.yonglian.management.domain.ActivityPlan;
import com.yonglian.management.repository.ActivityPlanRepository;
import com.yonglian.management.service.ActivityPlanService;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Service Implementation for managing {@link com.yonglian.management.domain.ActivityPlan}.
 */
@Service
@Transactional
public class ActivityPlanServiceImpl implements ActivityPlanService {

    private final Logger log = LoggerFactory.getLogger(ActivityPlanServiceImpl.class);

    private final ActivityPlanRepository activityPlanRepository;

    public ActivityPlanServiceImpl(ActivityPlanRepository activityPlanRepository) {
        this.activityPlanRepository = activityPlanRepository;
    }

    @Override
    public ActivityPlan save(ActivityPlan activityPlan) {
        log.debug("Request to save ActivityPlan : {}", activityPlan);
        return activityPlanRepository.save(activityPlan);
    }

    @Override
    public ActivityPlan update(ActivityPlan activityPlan) {
        log.debug("Request to update ActivityPlan : {}", activityPlan);
        return activityPlanRepository.save(activityPlan);
    }

    @Override
    public Optional<ActivityPlan> partialUpdate(ActivityPlan activityPlan) {
        log.debug("Request to partially update ActivityPlan : {}", activityPlan);

        return activityPlanRepository
            .findById(activityPlan.getId())
            .map(existingActivityPlan -> {
                if (activityPlan.getPlanName() != null) {
                    existingActivityPlan.setPlanName(activityPlan.getPlanName());
                }
                if (activityPlan.getCreateTime() != null) {
                    existingActivityPlan.setCreateTime(activityPlan.getCreateTime());
                }

                return existingActivityPlan;
            })
            .map(activityPlanRepository::save);
    }

    @Override
    @Transactional(readOnly = true)
    public Page<ActivityPlan> findAll(Pageable pageable) {
        log.debug("Request to get all ActivityPlans");
        return activityPlanRepository.findAll(pageable);
    }

    @Override
    @Transactional(readOnly = true)
    public Optional<ActivityPlan> findOne(Long id) {
        log.debug("Request to get ActivityPlan : {}", id);
        return activityPlanRepository.findById(id);
    }

    @Override
    public void delete(Long id) {
        log.debug("Request to delete ActivityPlan : {}", id);
        activityPlanRepository.deleteById(id);
    }
}
